package com.fr.report.script.function;

import com.fr.report.script.Function;
import com.fr.report.script.Function.Type;
import com.fr.report.script.NormalFunction;
import com.fr.report.script.Primitive;
import java.math.BigDecimal;

public class ENMONEY extends NormalFunction
{
  public Object run(Object[] paramArrayOfObject)
  {
    String str = "";
    if (paramArrayOfObject.length < 1)
      return Primitive.ERROR_NAME;
    for (int i = 0; i < paramArrayOfObject.length; ++i)
    {
      Object localObject = paramArrayOfObject[i];
      if (localObject instanceof BigDecimal)
        try
        {
          str = MoneyToEnglish((BigDecimal)localObject);
        }
        catch (Exception localException1)
        {
          str = "ERROR!";
        }
      if (localObject instanceof Number)
        try
        {
          BigDecimal localBigDecimal = new BigDecimal(((Number)localObject).doubleValue());
          str = MoneyToEnglish(localBigDecimal);
        }
        catch (Exception localException2)
        {
          str = "ERROR!";
        }
    }
    return str;
  }

  private String MoneyToEnglish(BigDecimal paramBigDecimal)
    throws Exception
  {
    int j;
    int k;
    int i7;
    int i8;
    String str1 = "";
    if (paramBigDecimal == null)
      return null;
    String str2 = paramBigDecimal.toString().trim();
    int i = str2.length();
    int l = str2.indexOf(".");
    if (l > 0)
    {
      j = i - l - 1;
      k = i - j - 1;
    }
    else
    {
      j = i;
      k = 0;
    }
    BigDecimal localBigDecimal = paramBigDecimal;
    int i1 = localBigDecimal.divide(new BigDecimal(100000000.0D), 0, 1).intValue();
    if (i1 > 9)
    {
      for (int i9 = 1; i9 <= j; ++i9)
        str1 = str1 + "*";
      str1 = str1 + ".";
      i9 = 1;
      while (true)
      {
        if (i9 > k)
          break label877;
        str1 = str1 + "*";
        ++i9;
      }
    }
    if (i1 > 0)
    {
      str1 = str1 + NumberToEnglish(new BigDecimal(i1)) + " HUNDRED ";
      i7 = 1;
    }
    else
    {
      i7 = 0;
    }
    localBigDecimal = localBigDecimal.add(new BigDecimal(i1 * 100000000).negate());
    int i2 = localBigDecimal.divide(new BigDecimal(1000000.0D), 0, 1).intValue();
    if (i2 > 0)
    {
      str1 = str1 + NumberToEnglish(new BigDecimal(i2)) + " ";
      i8 = 1;
    }
    else
    {
      i8 = 0;
    }
    if ((i7 != 0) || (i8 != 0))
      str1 = str1 + "MILLION ";
    localBigDecimal = localBigDecimal.add(new BigDecimal(i2 * 1000000).negate());
    int i3 = localBigDecimal.divide(new BigDecimal(100000.0D), 0, 1).intValue();
    if (i3 > 0)
    {
      str1 = str1 + NumberToEnglish(new BigDecimal(i3)) + " HUNDRED ";
      i7 = 1;
    }
    else
    {
      i7 = 0;
    }
    localBigDecimal = localBigDecimal.add(new BigDecimal(i3 * 100000).negate());
    int i4 = localBigDecimal.divide(new BigDecimal(1000.0D), 0, 1).intValue();
    if (i4 > 0)
    {
      str1 = str1 + NumberToEnglish(new BigDecimal(i4)) + " ";
      i8 = 1;
    }
    else
    {
      i8 = 0;
    }
    if ((i7 != 0) || (i8 != 0))
      str1 = str1 + "THOUSAND ";
    localBigDecimal = localBigDecimal.add(new BigDecimal(i4 * 1000).negate());
    int i5 = localBigDecimal.divide(new BigDecimal(100.0D), 0, 1).intValue();
    if (i5 > 0)
      str1 = str1 + NumberToEnglish(new BigDecimal(i5)) + " HUNDRED ";
    localBigDecimal = localBigDecimal.add(new BigDecimal(i5 * 100).negate());
    int i6 = localBigDecimal.divide(new BigDecimal(1.0D), 0, 1).intValue();
    if (i6 > 0)
      str1 = str1 + NumberToEnglish(new BigDecimal(i6));
    if (str1.trim().length() == 0)
      str1 = "ZERO";
    localBigDecimal = localBigDecimal.add(new BigDecimal(i6).negate());
    if (localBigDecimal.compareTo(new BigDecimal(0.0D)) > 0)
    {
      str1 = str1 + " AND CENTS ";
      localBigDecimal = localBigDecimal.multiply(new BigDecimal(100.0D)).divide(new BigDecimal(1.0D), 0, 4);
      str1 = str1 + NumberToEnglish(localBigDecimal);
    }
    label877: return str1;
  }

  private String NumberToEnglish(BigDecimal paramBigDecimal)
    throws Exception
  {
    int j;
    String str = "";
    int k = paramBigDecimal.intValue();
    if (k >= 20)
    {
      int i = k / 10 * 10;
      j = k - i;
      switch (i)
      {
      case 90:
        str = "NINETY";
        break;
      case 80:
        str = "EIGHTY";
        break;
      case 70:
        str = "SEVENTY";
        break;
      case 60:
        str = "SIXTY";
        break;
      case 50:
        str = "FIFTY";
        break;
      case 40:
        str = "FORTY";
        break;
      case 30:
        str = "THIRTY";
        break;
      case 20:
        str = "TWENTY";
      }
      if (str.trim().length() > 0)
        str = str + " ";
    }
    else
    {
      j = k;
    }
    switch (j)
    {
    case 19:
      str = str + "NINETEEN";
      break;
    case 18:
      str = str + "EIGHTEEN";
      break;
    case 17:
      str = str + "SEVENTEEN";
      break;
    case 16:
      str = str + "SIXTEEN";
      break;
    case 15:
      str = str + "FIFTEEN";
      break;
    case 14:
      str = str + "FOURTEEN";
      break;
    case 13:
      str = str + "THIRTEEN";
      break;
    case 12:
      str = str + "TWELVE";
      break;
    case 11:
      str = str + "ELEVEN";
      break;
    case 10:
      str = str + "TEN";
      break;
    case 9:
      str = str + "NINE";
      break;
    case 8:
      str = str + "EIGHT";
      break;
    case 7:
      str = str + "SEVEN";
      break;
    case 6:
      str = str + "SIX";
      break;
    case 5:
      str = str + "FIVE";
      break;
    case 4:
      str = str + "FOUR";
      break;
    case 3:
      str = str + "THREE";
      break;
    case 2:
      str = str + "TWO";
      break;
    case 1:
      str = str + "ONE";
    }
    return str;
  }

  public Function.Type getType()
  {
    return Function.TEXT;
  }

  public String getCN()
  {
    return "ENMONEY(value):将给定的BigDemical类型的数字转换成英文金额字符串。\n示例：\nENMONEY(23.49)等于TWENTY。";
  }

  public String getEN()
  {
    return "";
  }
}